local skel = fk.CreateSkill {
  name = "lb_zero__gujiang",
  max_branches_use_time = {
    ["round"] = {
      [Player.HistoryRound] = 1
    },
  },
}

local U = require "packages.utility.utility"

Fk:loadTranslationTable {
  ["lb_zero__gujiang"] = "锢匠",
  [":lb_zero__gujiang"] = "你可以跳过判定阶段并蓄谋牌堆顶的两张牌。每轮限一次，当你使用非手牌时，你摸两张牌。",

  ["#lb_zero__gujiang"] = "锢匠：你可以跳过判定阶段并蓄谋牌堆顶的两张牌",
  ["#lb_zero__gujiang_draw"] = "锢匠：你可以摸两张牌",

  ["$lb_zero__gujiang1"] = "开始实验吧。",
  ["$lb_zero__gujiang2"] = "我只负责技术相关。",
}


skel:addEffect(fk.EventPhaseChanging, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.phase == Player.Judge
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#lb_zero__gujiang" })
  end,
  on_use = function(self, event, target, player, data)
    data.skipped = true
    for i = 1, 2, 1 do
      U.premeditate(player, player.room:getNCards(1)[1], skel.name)
    end
  end,
})

skel:addEffect(fk.CardUsing, {  -- 来自 中流
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not (player:hasSkill(skel.name) and player == target and skel:withinBranchTimesLimit(player, "round", Player.HistoryRound)) then return end
    local cardlist = data.card:isVirtual() and data.card.subcards or { data.card.id }
    if #cardlist == 0 then return true end
    local no_skill = false
    local room = player.room
    local use_event = room.logic:getCurrentEvent()
    use_event:searchEvents(GameEvent.MoveCards, 1, function(e)
      if e.parent and e.parent.id == use_event.id then
        local subcheck = table.simpleClone(cardlist)
        for _, move in ipairs(e.data) do
          if move.moveReason == fk.ReasonUse then
            local handcard = false
            if move.from and move.from == player then
              handcard = true
            end
            for _, info in ipairs(move.moveInfo) do
              if table.removeOne(subcheck, info.cardId) and info.fromArea == Card.PlayerHand then
                if handcard then
                  no_skill = true
                end
              end
            end
          end
        end
        if #subcheck == 0 then
          return true
        end
      end
    end)
    return not no_skill
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#lb_zero__gujiang_draw" })
  end,
  on_use = function(self, event, target, player, data)
    player:addSkillBranchUseHistory(skel.name, "round")
    player:drawCards(2, skel.name)
  end,
})


return skel
